package com.dks.result;


/**
 * @author evan
 * @date 2020/4/16
 */
public class Result {

    public static <T> ResultModel makeResult(ResultInfo resultInfo){
        return makeResult(resultInfo, null);
    }

    public static <T> ResultModel makeResult(ResultInfo resultInfo, T t){
        return new ResultModel<>(resultInfo.getCode(), t, resultInfo.getMessage());
    }

    //返回信息格式化  eg: 编号：%s 的 %s
    public static <T> ResultModel makeResult(ResultInfo resultInfo, Object... formatObject){
        return makeResult(resultInfo, null, formatObject);
    }

    public static <T> ResultModel makeResult(ResultInfo resultInfo,  T t, Object... formatObject){
        return new ResultModel<>(resultInfo.getCode(), t, String.format(resultInfo.getMessage(), formatObject));
    }

    //返回信息之后添加部分信息
    public static <T> ResultModel makeResultAppend(ResultInfo resultInfo, String appendMessage){
        return makeResultAppend(resultInfo, null, appendMessage);
    }

    public static <T> ResultModel makeResultAppend(ResultInfo resultInfo,  T t, String appendMessage){
        return new ResultModel<>(resultInfo.getCode(), t, resultInfo.getMessage() + appendMessage);
    }




}
